<template>
  <div>
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item',item.id==0 ?'mui-active':null]"
            v-for="item in cates"
            :key="item.id"
            @click="getPic(item.id)"
          >{{item.title}}</a>
        </div>
      </div>
    </div>
    <ul class="photo-list">
      <router-link
        v-for="item in photolist"
        :key="item.id"
        :to="'photo/photoinfo/'+item.id"
        tag="li"
      >
        <img v-lazy="item.img_url" />
        <div class="img-explain">
          <h1>{{item.title}}</h1>
          <div class="img-zhaiyao">{{item.zhaiyao}}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

 <script>
import mui from "../../lib/mui/js/mui.js";

import { Toast } from "mint-ui";
export default {
  data() {
    return {
      cates: [],
      photolist: []
    };
  },
  created() {
    this.getAll();
    this.getPic(0);
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    getAll() {
      this.$http
        .get("http://www.liulongbin.top:3005/api/getimgcategory")
        .then(result => {
          if (result.body.status === 0) {
            result.body.message.unshift({ title: "全部", id: 0 });
            this.cates = result.body.message;
          } else {
            Toast("加载失败");
          }
        });
    },
    getPic(cateid) {
      this.$http
        .get("http://www.liulongbin.top:3005/api/getimages/" + cateid)
        .then(result => {
          if (result.body.status === 0) {
            this.photolist = result.body.message;
          } else {
            Toast("图片懒加载失败");
          }
        });
    }
  }
};
</script>

<style lang="scss" scoped>
* {
  touch-action: pan-y;
}

.photo-list {
  list-style: none;
  margin: 0px;
  padding: 10px;
  width: 100%;
  li {
    background-color: gray;
    text-align: center;
    padding: 5px;
    width: 100%;
    position: relative;
    img {
      width: 100%;
    }
    img[lazy="loading"] {
      width: 100%;
      height: 300px;
      margin: 5px;
    }

    .img-explain {
      position: absolute;
      bottom: 0;
      margin-bottom: 5px;
      color: white;
      max-height: 85px;
      h1 {
        font-size: 12px;
      }
      .img-zhaiyao {
        font-size: 10px;
      }
    }
  }
}
</style>